local skynet = require "skynet.manager"
local server_config = dofile(skynet.getenv("server_config"))

local max_client = tonumber(skynet.getenv "max_client")
local server_id = tonumber(skynet.getenv "server_id")

skynet.start(function()
	skynet.error("Server start")
	if not skynet.getenv "daemon" and server_config.no_cotainer then
		skynet.newservice("console")
	end
	local debug_listen_ip = "127.0.0.1"
	if not server_config.no_cotainer then
		debug_listen_ip = '0.0.0.0'
	end
	skynet.newservice("debug_console",debug_listen_ip, server_config.debug_port)
	
	skynet.uniqueservice("pbloader")
	local proxy_conn = skynet.newservice('proxy_conn')
	skynet.call(proxy_conn,'lua','start')

	local kafka_queue = skynet.newservice('kafka_queue')
	skynet.name('.kafka_queue',kafka_queue)

	local reload_service = skynet.uniqueservice('reload_service')
	skynet.name('.reload_service',reload_service)
	skynet.call(reload_service,'lua','pull_conf_data')

	local redis_config = {
		redis_host = server_config.redis_host,
		redis_port = tonumber(server_config.redis_port),
		redis_db = tonumber(server_config.redis_db),
		redis_auth = server_config.redis_auth,
		worker_num = 4,
	}

	local guid_mgr = skynet.newservice('common_service','worker_mgr')
	skynet.name('.guid_mgr',guid_mgr)
	redis_config.worker_name = 'guid_mgr'
	skynet.call(guid_mgr,'lua','start',redis_config)

	local msg_handler = skynet.newservice('msg_handler')
	skynet.name('.msg_handler',msg_handler)

	local info_mgr = skynet.newservice('info_mgr')
	skynet.name('.info_mgr',info_mgr)

	local robot_mgr = skynet.newservice('common_service','robot_mgr')
	skynet.name('.robot_mgr',robot_mgr)

	-- local web_proxy = skynet.newservice('web_proxy')
	-- skynet.name('.web_proxy',web_proxy)
	local web_proxy = skynet.newservice('common_service','proxy_mgr')
	skynet.name('.web_proxy',web_proxy)
	skynet.call(web_proxy,'lua','start',{proxy_num = 4})

	skynet.exit()
end)

